<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <title>Welcome to Vue</title>
</head>
<style>
    body {
        padding: 20px 200px;
        background-color: #ccc;

    }

    #app {
        background-color: #fff;
        border-radius: 15px;
        padding: 20px;
    }
</style>

<body>
    <div id="app">
        <nav>
            <el-input style="width: 200px;" v-model="search" placeholder="搜索内容"></el-input>
            <el-button type="primary" @click="SearchBtn">搜索</el-button>
            <el-button type="primary" icon="el-icon-edit" circle @click="dialogVisible= true"></el-button>
            <el-button type="danger" icon="el-icon-delete" circle @click="checkRemover"></el-button>
        </nav>
        <!-- 添加的框 -->
        <el-dialog title="提示" :visible.sync="dialogVisible" width="40%">
            <span>
                <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="活动名称">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item>
                    <el-form-item label="活动时间">
                        <el-col class="line" :span="2">-</el-col>
                        <el-col :span="11">
                            <el-time-picker placeholder="选择时间" v-model="form.date2" style="width: 100%;">
                            </el-time-picker>
                        </el-col>
                    </el-form-item>
                    <el-form-item label="活动性质">
                        <el-checkbox-group v-model="form.type">
                            <el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
                            <el-checkbox label="地推活动" name="type"></el-checkbox>
                            <el-checkbox label="线下主题活动" name="type"></el-checkbox>
                            <el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item label="特殊资源">
                        <el-radio-group v-model="form.resource">
                            <el-radio label="线上品牌商赞助"></el-radio>
                            <el-radio label="线下场地免费"></el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-form>


            </span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="addBtn">确 定</el-button>
            </span>
        </el-dialog>


        <!--数据渲染 -->
        <template>
            <el-table @selection-change="handleSelectionChange" :data="listMsg" style="width: 100%">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column prop="name" label="名称" width="180">
                </el-table-column>
                <el-table-column prop="date2" label="时间" width="180">
                </el-table-column>
                <el-table-column prop="type" label="内容" width="180">
                </el-table-column>
                <el-table-column prop="resource" label="资源" width="180">
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete( scope.row)">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </template>

        <!-- 编辑的弹窗 -->
        <el-dialog title="提示" :visible.sync="dialogVisibleEdit" width="40%">
            <span>
                <el-form ref="EditData" :model="EditData" label-width="80px">
                    <el-form-item label="活动名称">
                        <el-input v-model="EditData.name"></el-input>
                    </el-form-item>
                    <el-form-item label="活动时间">
                        <el-col class="line" :span="2">-</el-col>
                        <el-col :span="11">
                            <el-time-picker placeholder="选择时间" v-model="EditData.date2" style="width: 100%;">
                            </el-time-picker>
                        </el-col>
                    </el-form-item>
                    <el-form-item label="活动性质">
                        <el-checkbox-group v-model="EditData.type">
                            <el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
                            <el-checkbox label="地推活动" name="type"></el-checkbox>
                            <el-checkbox label="线下主题活动" name="type"></el-checkbox>
                            <el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item label="特殊资源">
                        <el-radio-group v-model="EditData.resource">
                            <el-radio label="线上品牌商赞助"></el-radio>
                            <el-radio label="线下场地免费"></el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-form>


            </span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="EditBtn(EditData)">编辑</el-button>
            </span>
        </el-dialog>
        <br>
        <div class="block">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :page-sizes="[5, 8, 10, 20]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
                :total="pageNum">
            </el-pagination>
        </div>
    </div>
</body>
<script src="./js/axios.js"></script>
<script src="./js/vue.js"></script>
<script src="./js/element.js"></script>
<script src="./js/jquery-1.12.3.js"></script>
<script>
    var vm = new Vue({
        el: '#app',
        data: {
            search: '',
            dialogVisible: false,
            dialogVisibleEdit: false,
            form: {
                name: '',
                date2: "",
                type: [],
                resource: '',
            },
            listMsg: [],
            EditData: [],
            checkData: [],
            pageNum: 0,  //分页总数据

            pageBtn: 1,
            pageSize: 5,
        },
        created() {
            this.render()
        },
        methods: {  // 发送函数
            addBtn() {
                this.dialogVisible = false
                console.log(this.form);
                axios.post('/add', this.form).then((result) => {
                    if (result.data.success) {
                        this.render()
                    }
                })
            },
            render() {  // 渲染函数
                axios.post('/fdd', { search: this.search, pageBtn: this.pageBtn, pageSize: this.pageSize }).then((result) => {
                    if (result.data.success) {
                        this.listMsg = result.data.list
                        this.pageNum = result.data.pageNum
                    }
                })
            },
            SearchBtn() {  // 搜索按钮
                this.render()
                console.log(this.search);
            },
            handleSelectionChange(item) {   // 复选框事件
                this.checkData = item
            },
            handleDelete(item) {  // 删除事件
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get('/sdd', { params: item }).then((result) => {
                        if (result.data.success) {
                            this.render()
                        }
                    }),
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });


            },
            handleEdit(item) {
                this.dialogVisibleEdit = true
                this.EditData = item
            },
            EditBtn(item) { // 编辑的事件
                this.dialogVisibleEdit = false
                axios.post('/edit', item).then((result) => {
                    if (result.data.success) {
                        this.render()
                    }
                })
            },
            checkRemover() {
                axios.post('/pdd', this.checkData).then((result) => {
                    if (result.data.success) {
                        this.render()
                    }
                })
            },
            handleCurrentChange(item) {  // 点击分页第几个
                this.pageBtn = item
                console.log(this.pageBtn);
                this.render()
            },
            handleSizeChange(item) {  // 一页展示多少条数据
                console.log(item);
                this.pageSize = item
                this.render()

            }

        },


    })

</script>

</html>